package com.laiyima.zhongjiang.linghuilv.demo.home;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.laiyima.zhongjiang.linghuilv.demo.R;

import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.text.DecimalFormat;

import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

public class TransactionInfoActivity extends SwipeBackActivity implements View.OnClickListener {
    private String TAG="TransactionInfoActivity";
    private int tiCode;
    private TextView ti_traAmount,ti_tranStatus,ti_cardType,ti_unionName,ti_traFees,ti_traDate,ti_orderNum,ti_serialNum;
    private LinearLayout linearLayout;
    protected boolean useThemestatusBarColor = false;//是否使用特殊的标题栏背景颜色，android5.0以上可以设置状态栏背景色，如果不使用则使用透明色值
    protected void setStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            //根据上面设置是否对状态栏单独设置颜色
            if (useThemestatusBarColor) {
                // getWindow().setStatusBarColor(getResources().getColor(R.color.colorTheme));
            } else {
                getWindow().setStatusBarColor(Color.TRANSPARENT);
            }
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0
            WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ) {//android6.0以后可以对状态栏文字颜色和图标进行修改
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusBar();
        setContentView(R.layout.activity_transaction_info);
        ti_traAmount= (TextView) findViewById(R.id.ti_traAmount);
        ti_tranStatus= (TextView) findViewById(R.id.ti_tranStatus);
        ti_cardType= (TextView) findViewById(R.id.ti_cardType);
        ti_unionName= (TextView) findViewById(R.id.ti_unionName);
        ti_traFees= (TextView) findViewById(R.id.ti_traFees);
        ti_traDate= (TextView) findViewById(R.id.ti_traDate);
        ti_orderNum= (TextView) findViewById(R.id.ti_orderNum);
        ti_serialNum= (TextView) findViewById(R.id.ti_serialNum);
        linearLayout= (LinearLayout) findViewById(R.id.ti_back);
        linearLayout.setOnClickListener(this);
        intView();
    }

    private void intView() {
        Intent intent = getIntent();
        String traid = intent.getStringExtra("traid");
        RequestParams params = new RequestParams("http://zljl.laiima.com/index.php?s=/lfl_api/Commonlfl/deal_detail");
        //需要带入的参数
        params.addBodyParameter("tra_id", traid);
         x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                try {

                    JSONObject jsonObjec = new JSONObject(result);
                    String data = jsonObjec.optString("data", null);
                    Log.e(TAG, "回调成功"+data);
                    if (!TextUtils.isEmpty(data)) {
                        JSONObject jsonObject = new JSONObject(data);
                        String traAmount = jsonObject.optString("traAmount", "");
                        Double a1 = Double.parseDouble(traAmount);
                        DecimalFormat decimalFormatq = new DecimalFormat("0.00");
                        String b1 = decimalFormatq.format(a1);
                        ti_traAmount.setText(b1+"元");
                        String tranStatus = jsonObject.optString("tranStatus", "");
                        ti_tranStatus.setText(tranStatus);
                        String serialNum = jsonObject.optString("serialNum", "");
                        ti_serialNum.setText(serialNum);
                        String traDate = jsonObject.optString("traDate", "");
                        ti_traDate.setText(traDate);
                        String orderNum = jsonObject.optString("orderNum", "");
                        ti_orderNum.setText(orderNum);
                        String unionName = jsonObject.optString("unionName", "");
                        ti_unionName.setText(unionName);
                        String cardType = jsonObject.optString("cardType", "");
                        ti_cardType.setText(cardType);
                        String traFees = jsonObject.optString("traFees", "");
                        Double a2 = Double.parseDouble(traFees);
                         String b2 = decimalFormatq.format(a2);
                        ti_traFees.setText(b2+"元");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (tiCode == 200) {
                }
                if (tiCode == 500) {
                    Toast.makeText(getApplicationContext(), "系统异常", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

                Log.e(TAG, "Throwable");
            }
            @Override
            public void onCancelled(CancelledException cex) {

            }
            @Override
            public void onFinished() {

            }
        });
    }

    @Override
    public void onClick(View v) {
        int id=v.getId();
        switch (id){
            case R.id.ti_back:
                finish();
                break;
        }
    }
}
